package com.oocl.ha.merchant.service.impl;

import java.util.List;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.oocl.ha.dao.DishDao;
import com.oocl.ha.entity.Dish;
import com.oocl.ha.merchant.service.DishManager;

@Service("mdm")
@Transactional
public class DishManagerImpl implements DishManager {
	
	@Autowired
	private DishDao dd;

	public int addDish(Dish dish, int mid) {
		return dd.addDish(dish, mid);
	}

	public int deleteDish(int dId) {
		return dd.deleteDish(dId);
	}

	public List<Dish> loadAllDish(int mId) {
		List<Dish> dList=dd.loadAllDish(mId);
		return dList;
	}

	public Dish findById(int did) {
		return dd.findById(did);
	}

	public int updateDish(Dish dish) {
		Dish d=dd.findById(dish.getDid());
		d.setDname(dish.getDname());
		d.setPrice(dish.getPrice());
		if (dish.getDicon()!=null) {
			d.setDicon(dish.getDicon());
		}
		return dish.getDid();
	}

	public int becomeRecommend(int did) {
		Dish dish=dd.findById(did);
		dish.setRecommend(1);
		return 1;
	}

	public int undercarriage(int did) {
		Dish dish=dd.findById(did);
		if (dish.getPrice()>0) {
			dish.setPrice(dish.getPrice()*(-1));			
		}
		return 1;
	}

}
